﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

using System.Linq.Expressions;
using System.Diagnostics;
using Small.Util.Data;
using System.Data;
using Small.Util.Reflection;
using System.Web.Mvc;
using System.Reflection;
using Small.Html.Entities;
using SmallProject.Models.Test;
using Small.Html.UI;
using System.Runtime.CompilerServices;
using Small.Express;

namespace test
{
    class Program
    {
      //  private static Expression<Func<T, string>> key;
       

        static void Main(string[] args)
        {




            DataClasses1DataContext linqContext = new DataClasses1DataContext();
            var datasource = linqContext.singer_info.Where(
                "singer_description == @0 and singer_description >@1 or 1==1 ", "1","2");

         Console.WriteLine(datasource.Count());
            //NewMethod();
            

        }

        private static void NewMethod()
        {
            List<TestModel> model = new List<TestModel>();
            model.Add(new TestModel { Key = 1, ParentID = 0, Name = "A", Age = 1 });
            model.Add(new TestModel { Key = 2, ParentID = 1, Name = "B", Age = 2 });
            model.Add(new TestModel { Key = 3, ParentID = 1, Name = "C", Age = 3 });
            model.Add(new TestModel { Key = 4, ParentID = 2, Name = "D", Age = 4 });
            model.Add(new TestModel { Key = 5, ParentID = 2, Name = "E", Age = 5 });
            model.Add(new TestModel { Key = 6, ParentID = 3, Name = "F", Age = 6 });
            model.Add(new TestModel { Key = 7, ParentID = 3, Name = "G", Age = 7 });
            model.Add(new TestModel { Key = 8, ParentID = 4, Name = "H", Age = 8 });
            model.Add(new TestModel { Key = 9, ParentID = 5, Name = "J", Age = 9 });
            model.Add(new TestModel { Key = 10, ParentID = 6, Name = "L", Age = 10 });
            model.Add(new TestModel { Key = 11, ParentID = 0, Name = "W", Age = 11 });

            TreeList list = GetTreeNode(model);

            IQueryable<TestModel> data = model.Select(p => p).AsQueryable();

            var s = data;

           

              Func<string,string> s1=b=>"D";



             
            var p1=  s1.ToString();
           

          Int32[] aaa={1,2};
          
            //foreach (var item in list.Nodes)
            //{

            //    Dispay(item);
            //}

            //Expression<Func<TestModel, string>> test1 = p => p.Name;
            //Func<TestModel, string> orderByTest = p => p.Name;
            ////model.OrderBy(test1.Body.);
        }
        private  static void Dispay(TreeNode node)
        {
            if (node.ChildNodes == null) { return; }
            Console.WriteLine(String.Format("{0}:{1}", node.Content.Key, node.Content.Parent));

            foreach (var item in node.ChildNodes)
            {

               

                Console.WriteLine(String.Format("{0}:{1}", item.Content.Key, item.Content.Parent));

                Dispay(item);
            }
        }

        private static TreeList GetTreeNode(List<TestModel> list)
        {
            TreeList treeList = new TreeList();
            treeList.Nodes = new List<TreeNode>();
            var parentNode = list.Where(p => p.ParentID == 0);
            foreach (var item in parentNode)
            {
                TreeNode node = new TreeNode();
                node.Content = new TreeItem { Key = Convert.ToString(item.Key), Parent = Convert.ToString(item.ParentID) };
                node.ChildNodes = new List<TreeNode>();
               
                GetNodeList(list, node);
                treeList.Nodes.Add(node);
            }


            return treeList;
        }
        private static void GetNodeList(IEnumerable<TestModel> list, TreeNode node)
        {

            var nodes = list.Where(p => Convert.ToString(p.ParentID).Equals(node.Content.Key));
            foreach (var item2 in nodes)
            {
                TreeNode node2 = new TreeNode();
                node2.Content = new TreeItem { Key = Convert.ToString(item2.Key), Parent = Convert.ToString(item2.ParentID) };
                if (node.ChildNodes == null)
                {
                    node.ChildNodes = new List<TreeNode>();
                }
                var nodes3 = list.Where(p => Convert.ToString(p.ParentID).Equals(node2.Content.Key));
                if (nodes3.Count() > 0)
                {

                    GetNodeList(list, node2);
                }

                node.ChildNodes.Add(node2);

            }
        }


        private static void GetName<T>(Expression<Func<T,object>> express)
        {
            string name = ExpressionHelper.GetExpressionText(express);
            string name1 = express.Name;
           var s= express.Compile().Target;
           var sss = express.Body.ToString();
           var s1 = express.Parameters;
           foreach (var item in s1)
           {
               var s2 = item.Type.Name;
           }
           
            
           
          
           //foreach (var item in ss)
           //{
               
           //}
          

           
            
           
        }
        private static void GetExpressMember<T>(Func<T,bool> func)
        {
           string s = func.Method.Name;
        }
        private static void ForEach<T>(T t)
        {

            Dictionary<string,string> anonymousNameList = DefinationProperties.GetProperties<T>(t);

            foreach (var item in anonymousNameList.Values)
            {
                string value = item;
            }
        }
        private static Expression<Func<SE_BudgetPlan, bool>> getSysDocumentPredicate()
        {
            Expression<Func<SE_BudgetPlan, bool>> expression1 = p => p.CreateUserID == 43348;
            Expression<Func<SE_BudgetPlan, bool>> expression2 = p => p.ModifyUserID == 1;
            Expression<Func<SE_BudgetPlan, bool>> expression3 = p => p.ExceedType ==null ;
           


            var expression = Expression.Lambda<Func<SE_BudgetPlan, bool>>(expression1.Body, expression1.Parameters);


            var invokedExpr = Expression<Func<SE_BudgetPlan, bool>>.Invoke(expression2, expression.Parameters);
            expression = Expression.Lambda<Func<SE_BudgetPlan, bool>>(Expression.And(expression.Body, invokedExpr), expression1.Parameters);


             var invokedExpr1 = Expression<Func<SE_BudgetPlan, bool>>.Invoke(expression3, expression1.Parameters); 
          

            expression = Expression.Lambda<Func<SE_BudgetPlan, bool>>(Expression.And(expression.Body, invokedExpr1), expression1.Parameters);
            return expression;
        }  
        


    }

    public class Student 
    {
        public Int32 StudentID { get; set; }
        public String StudentName { get; set; }
    }

    public class Test1<T> 
    {
        public Expression<Func<T, string>> key;
       

    
    }
}
